﻿using System;
using System.Collections.Generic;
using YArchitech.Controls;
using YArchitech.DataModel;

namespace YArchitech.Plumbing
{
	internal sealed class HotUsedWaterCalManage
	{
		private HotUsedWaterCalManage()
		{
			this.Initialize();
			this.GetDefaults();
		}

		public void Initialize()
		{
			try
			{
				if (this.HotDayCalArray == null || this.HotDayCalArray.Count <= 0)
				{
					this.HotDayCalArray = new List<HotUsedWaterCal>();
					this.HotDayCalArray = HYCalSQLData.GetHotUsedWaterDayData();
				}
				if (this.HotHourCalArray == null || this.HotHourCalArray.Count <= 0)
				{
					this.HotHourCalArray = new List<HotUsedWaterCal>();
					this.HotHourCalArray = HYCalSQLData.GetHotUsedWaterHourData();
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.ToString());
			}
		}

		public List<HotUsedWaterCal> GetHotDayCalArray
		{
			get
			{
				return this.HotDayCalArray;
			}
		}

		public List<HotUsedWaterCal> GetHotHourCalArray
		{
			get
			{
				return this.HotHourCalArray;
			}
		}

		public void GetDefaults()
		{
			try
			{
				UserSetting userSetting = new UserSetting();
				string value = userSetting.GetValue("HotUsedWaterCalManage", "bIsCalForDay");
				if (!string.IsNullOrEmpty(value))
				{
					if (value == "true")
					{
						this.bIsCalForDay = true;
					}
					else
					{
						this.bIsCalForDay = false;
					}
				}
				value = userSetting.GetValue("HotUsedWaterCalManage", "HotTemp");
				if (!string.IsNullOrEmpty(value))
				{
					this.HotTemp = Math.Round(Convert.ToDouble(value), 1);
				}
				value = userSetting.GetValue("HotUsedWaterCalManage", "ColdTemp");
				if (!string.IsNullOrEmpty(value))
				{
					this.ColdTemp = Math.Round(Convert.ToDouble(value), 1);
				}
			}
			catch
			{
			}
		}

		public void SetDefaults()
		{
			UserSetting userSetting = new UserSetting();
			userSetting.WriteValue("HotUsedWaterCalManage", "bIsCalForDay", this.bIsCalForDay.ToString());
			userSetting.WriteValue("HotUsedWaterCalManage", "HotTemp", this.HotTemp.ToString());
			userSetting.WriteValue("HotUsedWaterCalManage", "ColdTemp", this.ColdTemp.ToString());
		}

		public static readonly HotUsedWaterCalManage Instance = new HotUsedWaterCalManage();

		public bool bIsCalForDay = true;

		public double HotTemp = 60.0;

		public double ColdTemp = 10.0;

		public List<HotUsedWaterCal> HotDayCalArray;

		public List<HotUsedWaterCal> HotHourCalArray;
	}
}
